package cn.edu.suda.schoolBus.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.suda.schoolBus.bean.Passenger;
import cn.edu.suda.schoolBus.bean.PassengerExample;
import cn.edu.suda.schoolBus.dao.PassengerMapper;
import cn.edu.suda.schoolBus.service.PassengerService;

@Service
public class PassengerServiceImpl implements PassengerService {

	@Autowired
	private PassengerMapper passengerDao;

	private PassengerExample passengerExample;

	@Override
	public int addPassenger(Passenger passenger) {
		passenger.setpTime(new Date());
		return passengerDao.insertSelective(passenger);
	}

	@Override
	public Passenger getPassenger(String username, String passwd) {
		passengerExample = new PassengerExample();
		passengerExample.createCriteria().andPAccountEqualTo(username).andPPasswdEqualTo(passwd);
		List<Passenger> passengers = passengerDao.selectByExample(passengerExample);
		Passenger passenger = null;
		if (passengers.size() == 1) {
			passenger = passengers.get(0);
		}
		return passenger;
	}

}
